#define _CRT_SECURE_NO_DEPRECATE
#pragma comment (linker, "/STACK:30000000")

#include <string>
#include <vector>
#include <cmath>
//#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
//#include <cstdio>
//#include <sstream>
#include <cassert>
//#include <utility>

using namespace std;

#define EPS 1E-8
const int INF = (int)1E+9;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define forv(i, v) for (int i = 0; i < (int)(v.size()); ++i)
#define fors(i, s) for (int i = 0; i < (int)(s.length()); ++i)
#define all(a) a.begin(), a.end()
#define pb push_back
#define PII pair<int, int>
#define mp make_pair
#define VI vector<int>
#define VS vector<string>
#define norm(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define num(a, v) (int)(lower_bound(all(a), v) - a.begin())

FILE *f = 0;
int tst = 0;

void close() {
    if (f != 0) {
        fclose(f);
        f = 0;
    }
}

FILE *open() {
    close();
    char fname[10];
    sprintf(fname, "%.2d", ++tst);
    cerr << tst << endl;
    return f = fopen(fname, "wt");
}

int random(int value)
{
    return ((((unsigned int)rand()) << 15) ^ ((unsigned int)rand())) % value;
}

int n, m;
int a[1000][1000];

void outTest() {
    open();
    fprintf(f, "%d %d\n", n, m);
    forn(i, n) {
        forn(j, m) {
            if (j > 0) fprintf(f, " ");
            fprintf(f, "%d", a[i][j]);
        }
        fprintf(f, "\n");
    }
}

const int MAX_VALUE = (int)1e+9 + 1;
const int numtst = 5;
int ns[numtst] = {30, 90, 111, 234, 300};

typedef vector< pair<int, int> > graph;

void ejik_column() {
    cerr << "ejik_column" << endl;
    forn(ii, numtst) {
        m = 1;
        n = ns[ii];
        set<int> s;
        while ((int)s.size() < n) s.insert(random(MAX_VALUE));
        vector<int> c(all(s));
        random_shuffle(all(c));
        forn(i, n) a[i][0] = c[i];
        outTest();
    }
}

void line() {
    cerr << "ejik_column" << endl;
    forn(ii, numtst) {
        n = 1;
        m = ns[ii];
        set<int> s;
        while ((int)s.size() < m) s.insert(random(MAX_VALUE));
        vector<int> c(all(s));
        random_shuffle(all(c));
        forn(i, n) a[0][i] = c[i];
        outTest();
    }
}

void any_graph(graph& g) {
    norm(g);
    random_shuffle(all(g));
    n = (int)g.size() + 1;
    m = (int)g.size();
    vector<int> p(g.size());
    forv(i, p) p[i] = i + 1;
    random_shuffle(all(p));
    forv(i, g) {
        int u = g[i].first;
        int v = g[i].second;
        if (random(2)) swap(u, v);
        forn(j, n) a[j][i] = u;
        a[p[i]][i] = v;
    }
    outTest();
}

vector<int> getVertexes(int n) {
    set<int> s;
    while ((int)s.size() < n) s.insert(random(MAX_VALUE));
    vector<int> c(all(s));
    random_shuffle(all(c));
    return c;
}

void circle() {
    cerr << "circle" << endl;
    forn(ii, numtst) {
        graph g;
        int n = ns[ii] - 1;
        vector<int> c = getVertexes(n);
        forv(i, c) g.pb(mp(c[i], c[(i + 1) % c.size()]));
        any_graph(g);
    }
}

void full() {
    cerr << "full" << endl;
    forn(ii, numtst) {
        graph g;
        int n = (int)sqrt(ns[ii] * 2.0);
        vector<int> c = getVertexes(n);
        forv(i, c) 
            forn(j, i) {
                g.pb(mp(c[i], c[j]));
            }
        any_graph(g);
    }
}

void clicks() {
    cerr << "clicks" << endl;
    forn(ii, numtst) {
        graph g;
        int n = (int)sqrt(ns[ii] * 2.0);
        vector<int> c = getVertexes(n);
        int t = 0;
        while (t < ns[ii]) {
            vector<int> x;
            forv(i, c) {
                int sz = (int)x.size();
                if (random(2) && t + sz * (sz + 1) / 2 <= ns[ii]) x.pb(c[i]);
            }
            int sz = (int)x.size();
            t += sz * (sz - 1) / 2;
            forv(i, x) 
                forn(j, i) {
                    g.pb(mp(x[i], x[j]));
                }
        }
        any_graph(g);
    }
}

void tree() {
    cerr << "tree" << endl;
    forn(ii, numtst) {
        graph g;
        int n = (int)sqrt(ns[ii] * 2.0);
        vector<int> c = getVertexes(n);
        forv(i, c) if (i > 0) {
            g.pb(mp(c[i], c[random(i)]));
        }
        any_graph(g);
    }
}

void random_graph(int numvertex) {
    cerr << "random_graph, numvertex = " << numvertex << endl;
    forn(ii, numtst) {
        graph g;
        int n = ns[ii] - 1;
        vector<int> c = getVertexes(numvertex);
        forn(i, n) {
            int u = 0, v = 0;
            while (u == v) {
                u = c[random(c.size())];
                v = c[random(c.size())];
            }
            g.pb(mp(u, v));
        }
        any_graph(g);
    }
}

void random_table(int maxval) {
    cerr << "random_table, maxval = " << maxval << endl;
    forn(ii, numtst) {
        graph g;
        n = ns[ii];
        m = random(n) + 1;
        if (random(2)) swap(n, m);
        forn(i, n) forn(j, m) a[i][j] = random(maxval);
        outTest();
    }
}

void sample() {
    cerr << "sample" << endl;
    open();
    fprintf(f, "1 5\n1 2 3 4 5\n");
    open();
    fprintf(f, "2 2\n1 2\n1 3\n");
    open();
    fprintf(f, "4 2\n0 2\n4 5\n7 6\n3 1\n");
}

void solve() {
    sample();
    ejik_column();
    line();
    circle();
    full();
    tree();
    clicks();
    random_graph(2000);
    random_graph(100);
    random_graph(50);

    random_table(50);
    random_table(1000);
    random_table(1000000001);
}

int main() 
{
    solve();
    close();
    return 0;
}

